<?php
session_status();
$username =trim($_POST['username']);
$pw =trim($_POST['pw']);
$usernameReg ='/^[a-zA-Z0-9_\-@#*]{3,11}$/';
if (!preg_match($usernameReg,$username)){
    echo "<script>alert('用户名只能是大小写字母, 数字长度3-11!!');history.back();</script>";exit;
}
$pwReg ='/^[a-zA-Z0-9@#*_\-]{6,11}$/';
if (!preg_match($pwReg,$pw)){
    echo "<script>alert('密码只能是大小写字母，数字,-,_,*,长度为6-11!');history.back()</script>";
    exit();
}
$pw=md5($pw);
include 'coon.php';
$sql ="select * from userinfo where username= '$username'and pw='$pw'";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result)){
    echo "<script>alert('登录成功!');location.href='index.php';</script>";
//    $_SESSION['isLogged']=1;
    $_SESSION['loggedUsername']=$username;
}
else{
    echo "<script>alert('用户名或密码错误!');history.back();</script>";
    session_destroy();
}